package com.mj.action;

import java.util.List;
import java.util.Map;
import java.util.Set;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.mj.model.system.Menu;
import com.mj.model.system.User;
import com.mj.service.system.MenuService;
import com.mj.util.CommonUtil;

/**
 * 首页
 *@ClassName:HomeAction.java
 *@author dsc
 *@date 2017年7月21日
 *@Description TODO
 *
 */
@Controller
public class HomeAction{
	@Resource
	private CommonUtil commonUtil;
	@Resource
	private MenuService menuService;
    /**
     * 后台首页
     * 
     * @param req
     * @param model
     * @return
     */
//    @RequestMapping("/")
//    public String index(HttpServletRequest req, Model model){
//        return "map/map";
//    }
    
    
   
    @RequestMapping("")
    public String home(HttpServletRequest req, Model model){
    	User loginUser = (User)req.getAttribute("user");
    	//当前角色对应的菜单id
    	Set<String> mids = menuService.getMenusByPermisson(loginUser.getRoleId());
    	// 后台左侧栏目列表
    	List<Menu> menulist = menuService.getMenuByIdList(mids.toArray(new String[]{}),"");
    	List<Map<String,Object>> ml = commonUtil.treeMapList(menulist, 0);
    	req.setAttribute("menuData", ml);
    	
    	return "index";
    }
    
    
    
}
